<!--
 * @Description:
 * @version:
 * @Author: sunqian_sr
 * @Date: 2022-10-10 13:52:52
 * @LastEditors: Andy
 * @LastEditTime: 2023-03-10 15:36:33
-->
<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
  import { Socket } from '@package/service/src/lib/websocket.js'
  import { mapActions } from 'pinia'
  import { pinias } from '@/common/pinia'

  const { login } = pinias
  export default {
    name: 'App',
    data() {
      return {
        websocket: null
      }
    },
    created() {
      this.initWebSocket()
    },
    methods: {
      ...mapActions(login, ['getUserUnreadCount']),
      initWebSocket() {
        this.websocket = new Socket({
          url: '/prod-api/ws/websocket?userId=4353521331&topic=notice',
          sendData: {
            sender: 1 // todo 待完成其他逻辑
          },
          onMessage: this.onMessage
        })
      },
      onMessage(data) {
        console.log('获取到的消息', data)
        this.getUserUnreadCount()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .main {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 100px;
  }
</style>
